<template>
	<main-container>
		<!-- 搜索 -->
		<el-form :model="state.queryParams" ref="queryRef" :inline="true" v-show="showSearch">
					<el-button type="primary" @click="initPage"><el-icon> <ele-Search /> </el-icon>搜索</el-button>
			<el-button @click="resetQuery"><el-icon> <ele-Refresh /> </el-icon>重置</el-button>
		</el-form>
		<!-- 工具栏 -->
		<div class="hx-table-toolbar">
			<div>
				<el-button type="primary" v-auth="'weixin:wxapp:add'" @click="add"
				><el-icon> <ele-Plus /> </el-icon>新增</el-button
				>
			</div>
			<right-toolbar :searchBtn="true" :refreshBtn="true" @search="showSearch = !showSearch" @refresh="initPage"></right-toolbar>
		</div>
		<Form ref="formRef" @initPage="initPage"></Form>
		<!-- 列表 -->
		<el-table v-loading="loading" :data="state.tableData" border>
			<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
					<el-table-column prop="id" label="主键" header-align="center" align="center"></el-table-column>
					<el-table-column prop="distributionNo" label="配送单号" header-align="center" align="center"></el-table-column>
					<el-table-column prop="orderNo" label="交易订单号" header-align="center" align="center"></el-table-column>
					<el-table-column prop="orderPrice" label="订单金额" header-align="center" align="center"></el-table-column>
					<el-table-column prop="cityCode" label="订单所在城市编码" header-align="center" align="center"></el-table-column>
					<el-table-column prop="fetchAddress" label="取货地址" header-align="center" align="center"></el-table-column>
					<el-table-column prop="expectedFetchTime" label="期望取货时间戳(当前时间戳往后推15分钟)" header-align="center" align="center"></el-table-column>
					<el-table-column prop="defaultAffirmTime" label="默认配送完成时间" header-align="center" align="center"></el-table-column>
					<el-table-column prop="destinationName" label="收货人姓名" header-align="center" align="center"></el-table-column>
					<el-table-column prop="destinationTel" label="收货人手机号" header-align="center" align="center"></el-table-column>
					<el-table-column prop="destinationAddress" label="收货人地址" header-align="center" align="center"></el-table-column>
					<el-table-column prop="destinationLng" label="收货人地址经度(高德坐标系)" header-align="center" align="center"></el-table-column>
					<el-table-column prop="destinationLat" label="收货人地址纬度(高德坐标系)" header-align="center" align="center"></el-table-column>
					<el-table-column prop="status" label="配送单状态(0：未开始，1：配送中，2：已完成，3：已取消)" header-align="center" align="center"></el-table-column>
					<el-table-column prop="createTime" label="创建时间" header-align="center" align="center"></el-table-column>
					<el-table-column prop="updateTime" label="更新时间" header-align="center" align="center"></el-table-column>
					<el-table-column prop="delFlag" label="逻辑删除：0.显示；1.隐藏；" header-align="center" align="center"></el-table-column>
					<el-table-column prop="tenantId" label="租户id" header-align="center" align="center"></el-table-column>
					<el-table-column prop="createBy" label="创建人" header-align="center" align="center"></el-table-column>
					<el-table-column prop="updateBy" label="修改人" header-align="center" align="center"></el-table-column>
			<el-table-column label="操作" width="200" align="center" fixed="right">
				<template #default="scope">
					<el-button link type="primary" @click="edit(scope.row)" v-auth="'cloud:distribution_order:edit'"
					><el-icon> <ele-Edit /> </el-icon>修改</el-button
					>
					<el-button link type="danger" @click="del(scope.row.appId)" v-auth="'cloud:distribution_order:del'"
					><el-icon> <ele-Delete /> </el-icon>删除</el-button
					>
				</template>
			</el-table-column>
		</el-table>
		<!-- 分页 -->
		<pagination
				v-model:total="state.page.total"
				v-model:currentPage="state.page.currentPage"
				v-model:pageSize="state.page.pageSize"
				@changePage="initPage"
		></pagination>
	</main-container>
</template>

<script setup lang="ts" name="clouddistribution_orderIndex">
	import { defineAsyncComponent, ref, reactive } from 'vue';
	import { ElMessageBox, ElMessage } from 'element-plus';
	import { getPage, delObj } from '/@/api/cloud/distribution_order';
	const Form = defineAsyncComponent(() => import('./form.vue'));
	const state = reactive({
		queryParams: {
		},
		page: {
			total: 0, // 总页数
			currentPage: 1, // 当前页数
			pageSize: 10, // 每页显示多少条
			ascs: [],
			descs: 'create_time',
		},
		tableData: [],
	})

const showSearch = ref(true);
const loading = ref(false);
const formRef = ref();
/**
 * init
 */
const initPage = async () => {
	loading.value = true;

	await getPage(Object.assign(state.page, state.queryParams))
			.then((response: any) => {
				state.tableData = response.data.data.records;
				state.page.total = response.data.data.total;
				loading.value = false;
			})
			.catch(() => {
				loading.value = false;
			});
};
/**
 * 重置搜索表单
 */
const resetQuery = () => {
	state.queryParams = {
	};
	initPage()
};
/**
 * 新增按钮
 */
const add = () => {
	formRef.value.initForm();
};
/**
 * 修改按钮
 */
const edit = (row: any) => {
	formRef.value.initForm(row);
};
/**
 * 删除按钮
 */
const del = (id: string) => {
	ElMessageBox.confirm('此操作将删除该微信应用，是否继续?', '提示', {
		confirmButtonText: '确认',
		cancelButtonText: '取消',
		type: 'warning',
	}).then(() => {
		delObj(id)
				.then((response) => {
					ElMessage.success('删除成功');
					initPage();
				})
				.catch(() => {});
	});
};
initPage();
</script>
